package com.sdry.utils;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.sdry.model.lqy.Workstation;
import com.sdry.model.lqy.WorkstationDetail;

public class WorkstationUtil {
 
	public static List<Workstation> Sum(List<Workstation> workstation){
		WorkstationDetail workstationDetail1=new WorkstationDetail();
		WorkstationDetail workstationDetail2=new WorkstationDetail();
		WorkstationDetail workstationDetail3=new WorkstationDetail();
		WorkstationDetail workstationDetail4=new WorkstationDetail();
		WorkstationDetail workstationDetail5=new WorkstationDetail();
		WorkstationDetail workstationDetail6=new WorkstationDetail();
		WorkstationDetail workstationDetail7=new WorkstationDetail();
		WorkstationDetail workstationDetail8=new WorkstationDetail();
		WorkstationDetail workstationDetail9=new WorkstationDetail();
		WorkstationDetail workstationDetail10=new WorkstationDetail();
		WorkstationDetail workstationDetail11=new WorkstationDetail();
		WorkstationDetail workstationDetail12=new WorkstationDetail();
		WorkstationDetail workstationDetail13=new WorkstationDetail();
		for(int iii=0;iii<workstation.size();iii++) {
			workstationDetail1.add(workstation.get(iii).getHot1());
			workstationDetail2.add(workstation.get(iii).getHot2());
			workstationDetail3.add(workstation.get(iii).getHot3());
			workstationDetail4.add(workstation.get(iii).getHot4());
			workstationDetail5.add(workstation.get(iii).getWet1());
			workstationDetail6.add(workstation.get(iii).getWet1());
			workstationDetail7.add(workstation.get(iii).getAssemble());
			workstationDetail8.add(workstation.get(iii).getSolid());
			workstationDetail9.add(workstation.get(iii).getCentrifugal());
			workstationDetail10.add(workstation.get(iii).getCut());
			workstationDetail11.adds(workstation.get(iii).getLeak());
			workstationDetail12.adds(workstation.get(iii).getRun());
			workstationDetail13.adds(workstation.get(iii).getAirtight());
		}
		Workstation workstation2=new Workstation();
		workstation2.setHot1(workstationDetail1);
		workstation2.setHot2(workstationDetail2);
		workstation2.setHot3(workstationDetail3);
		workstation2.setHot4(workstationDetail4);
		workstation2.setWet1(workstationDetail5);
		workstation2.setWet2(workstationDetail6);
		workstation2.setAssemble(workstationDetail7);
		workstation2.setSolid(workstationDetail8);
		workstation2.setCentrifugal(workstationDetail9);
		workstation2.setCut(workstationDetail10);
		workstation2.setLeak(workstationDetail11);
		workstation2.setRun(workstationDetail12);
		workstation2.setAirtight(workstationDetail13);
		workstation2.setTime(workstation.get(workstation.size()-1).getTime());
		workstation2.setTeam("总计");
		DecimalFormat decimalFormat=new DecimalFormat(".00");
		if(null == workstation2.getHot1().getFact() || "".equals(workstation2.getHot1().getFact())){
			workstation2.getHot1().setFact("0");
		}
		String hot1different = "";
		if(null == workstation2.getHot1().getTheory() || "".equals(workstation2.getHot1().getTheory())){
			workstation2.getHot1().setTheory("0");
			hot1different="0.00%";
		}else{
			hot1different=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getHot1().getFact())/
					Integer.parseInt(workstation2.getHot1().getTheory()))+"%";
			if(hot1different.equals(".00%")||hot1different.equals("�%")) {
				hot1different="0.00%";
			}
		}
		
		workstation2.getHot1().setDifference(hot1different);
		
		if(null == workstation2.getHot2().getFact() || "".equals(workstation2.getHot2().getFact())){
			workstation2.getHot2().setFact("0");
		}
		String hot2different = "";
		if(null == workstation2.getHot2().getTheory() || "".equals(workstation2.getHot2().getTheory())){
			workstation2.getHot2().setTheory("0");
			hot2different="0.00%";
		}else{
			hot2different=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getHot2().getFact())/
					Integer.parseInt(workstation2.getHot2().getTheory()))+"%";
			if(hot2different.equals(".00%")||hot2different.equals("�%")) {
				hot2different="0.00%";
			}
		}
		workstation2.setHot2(workstationDetail2);
		workstation2.getHot2().setDifference(hot2different);
		
		if(null == workstation2.getHot3().getFact() || "".equals(workstation2.getHot3().getFact())){
			workstation2.getHot3().setFact("0");
		}
		String hot3different = "";
		if(null == workstation2.getHot3().getTheory() || "".equals(workstation2.getHot3().getTheory())){
			workstation2.getHot3().setTheory("0");
			hot3different="0.00%";
		}else{
			hot3different=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getHot3().getFact())/
					Integer.parseInt(workstation2.getHot3().getTheory()))+"%";
			if(hot3different.equals(".00%")||hot3different.equals("�%")) {
				hot3different="0.00%";
			}
		}
		workstation2.setHot3(workstationDetail3);
		workstation2.getHot3().setDifference(hot3different);
		
		if(null == workstation2.getHot4().getFact() || "".equals(workstation2.getHot4().getFact())){
			workstation2.getHot4().setFact("0");
		}
		String hot4different = "";
		if(null == workstation2.getHot4().getTheory() || "".equals(workstation2.getHot4().getTheory())){
			workstation2.getHot4().setTheory("0");
			hot4different="0.00%";
		}else{
			hot4different=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getHot4().getFact())/
					Integer.parseInt(workstation2.getHot4().getTheory()))+"%";
			if(hot4different.equals(".00%")||hot4different.equals("�%")) {
				hot4different="0.00%";
			}
		}
		
		workstation2.setHot4(workstationDetail4);
		workstation2.getHot4().setDifference(hot4different);
		
		if(null == workstation2.getWet1().getFact() || "".equals(workstation2.getWet1().getFact())){
			workstation2.getWet1().setFact("0");
		}
		String hot5different="";
		if(null == workstation2.getWet1().getTheory() || "".equals(workstation2.getWet1().getTheory())){
			workstation2.getWet1().setTheory("0");
			hot5different="0.00%";
		}else{
			hot5different=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getWet1().getFact())/
					Integer.parseInt(workstation2.getWet1().getTheory()))+"%";
			if(hot5different.equals(".00%")||hot5different.equals("�%")) {
				hot5different="0.00%";
			}
		}
		
		workstation2.setWet1(workstationDetail5);
		workstation2.getWet1().setDifference(hot5different);
		
		if(null == workstation2.getWet2().getFact() || "".equals(workstation2.getWet2().getFact())){
			workstation2.getWet2().setFact("0");
		}
		String hot6different="";
		if(null == workstation2.getWet2().getTheory() || "".equals(workstation2.getWet2().getTheory())){
			workstation2.getWet2().setTheory("0");
			hot6different="0.00%";
		}else{
			hot6different=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getWet2().getFact())/
					Integer.parseInt(workstation2.getWet2().getTheory()))+"%";
			if(hot6different.equals(".00%")||hot6different.equals("�%")) {
				hot6different="0.00%";
			}
		}
		
		workstation2.setWet2(workstationDetail6);
		workstation2.getWet2().setDifference(hot6different);
		
		if(null == workstation2.getAssemble().getFact() || "".equals(workstation2.getAssemble().getFact())){
			workstation2.getAssemble().setFact("0");
		}
		String Assembledifferent="";
		if(null == workstation2.getAssemble().getTheory() || "".equals(workstation2.getAssemble().getTheory())){
			workstation2.getAssemble().setTheory("0");
			Assembledifferent="0.00%";
		}else{
			Assembledifferent=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getAssemble().getFact())/
					Integer.parseInt(workstation2.getAssemble().getTheory()))+"%";
			if(Assembledifferent.equals(".00%")||Assembledifferent.equals("�%")) {
				Assembledifferent="0.00%";
			}
		}
		
		workstation2.setAssemble(workstationDetail7);
		workstation2.getAssemble().setDifference(Assembledifferent);
		
		if(null == workstation2.getSolid().getFact() || "".equals(workstation2.getSolid().getFact())){
			workstation2.getSolid().setFact("0");
		}
		String Soliddifferent="";
		if(null == workstation2.getSolid().getTheory() || "".equals(workstation2.getSolid().getTheory())){
			workstation2.getSolid().setTheory("0");
			Soliddifferent="0.00%";
		}else{
			Soliddifferent=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getSolid().getFact())/
					Integer.parseInt(workstation2.getSolid().getTheory()))+"%";
			if(Soliddifferent.equals(".00%")||Soliddifferent.equals("�%")) {
				Soliddifferent="0.00%";
			}
		}
		
		workstation2.setSolid(workstationDetail8);
		workstation2.getSolid().setDifference(Soliddifferent);
		
		if(null == workstation2.getCentrifugal().getFact() || "".equals(workstation2.getCentrifugal().getFact())){
			workstation2.getCentrifugal().setFact("0");
		}
		String Centrifugaldifferent="";
		if(null == workstation2.getCentrifugal().getTheory() || "".equals(workstation2.getCentrifugal().getTheory())){
			workstation2.getCentrifugal().setTheory("0");
			Centrifugaldifferent="0.00%";
		}else{
			Centrifugaldifferent=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getCentrifugal().getFact())/
					Integer.parseInt(workstation2.getCentrifugal().getTheory()))+"%";
			if(Centrifugaldifferent.equals(".00%")||Centrifugaldifferent.equals("�%")) {
				Centrifugaldifferent="0.00%";
			}
		}
		
		workstation2.setCentrifugal(workstationDetail9);
		workstation2.getCentrifugal().setDifference(Centrifugaldifferent);
		
		if(null == workstation2.getCut().getFact() || "".equals(workstation2.getCut().getFact())){
			workstation2.getCut().setFact("0");
		}
		String Cutdifferent="";
		if(null == workstation2.getCut().getTheory() || "".equals(workstation2.getCut().getTheory())){
			workstation2.getCut().setTheory("0");
			Cutdifferent="0.00%";
		}else{
			Cutdifferent=decimalFormat.format(100*(double)Integer.parseInt(workstation2.getCut().getFact())/
					Integer.parseInt(workstation2.getCut().getTheory()))+"%";
			if(Cutdifferent.equals(".00%")||Cutdifferent.equals("�%")) {
				Cutdifferent="0.00%";
			}
		}
		
		workstation2.setCut(workstationDetail10);
		workstation2.getCut().setDifference(Cutdifferent);
		
		
		workstation2.setLeak(workstationDetail11);
		workstation2.setRun(workstationDetail12);
		workstation2.setAirtight(workstationDetail13);
		
		
		
		workstation.add(workstation2);
		return workstation;
	}

}
